package com.easylinkin.linkappapi.lobar.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.annotation.CommonOperateLogAnnotate;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.lobar.dto.VisitorRecordDTO;
import com.easylinkin.linkappapi.lobar.entity.VisitorRecord;
import com.easylinkin.linkappapi.lobar.service.VisitorRecordService;
import com.easylinkin.linkappapi.lobar.vo.VisitorRecordStatusVO;
import com.easylinkin.linkappapi.operatelog.constant.LogConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 来访人员记录 前端控制器
 * </p>
 *
 * @author Xiaoyang
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/lobar/visitorRecord")
@Api(tags = "来访记录管理")
public class VisitorRecordController {

  @Autowired
  private VisitorRecordService visitorRecordService;

  @PostMapping("add")
  @ApiOperation("新增来访记录")
  public RestMessage add(@RequestBody VisitorRecord visitorRecord){
    Assert.notNull(visitorRecord, "visitorRecord 不能为空");
    Assert.notNull(visitorRecord.getTenantId(), "tenantId 不能为空");
    Assert.notNull(visitorRecord.getName(), "name 不能为空");
    Assert.notNull(visitorRecord.getCompany(), "company 不能为空");
    Assert.notNull(visitorRecord.getPhone(), "phone 不能为空");
    Assert.notNull(visitorRecord.getIdCard(), "idCard 不能为空");
    //【ID1006417】【app/劳务管理】来访人员移除防疫相关字段
    // 移除字段：从何地来，体温，三码是否正常，武汉核酸码字段
    /*Assert.notNull(visitorRecord.getTemperature(), "temperature 不能为空");
    Assert.notNull(visitorRecord.getStartPlace(), "startPlace 不能为空");
    Assert.notNull(visitorRecord.getHealthCodeStatus(), "healthCodeStatus 不能为空");
    Assert.notNull(visitorRecord.getTwentyfourTestStatus(), "twentyfourTestStatus 不能为空");*/
    visitorRecordService.add(visitorRecord);
    return RestBuilders.successBuilder().build();
  }

  @PostMapping("listPage")
  @ApiOperation("根据条件，分页(不分页)查询来访记录")
  public RestMessage listPage(@RequestBody RequestModel<VisitorRecordDTO> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<VisitorRecord> record = visitorRecordService.listPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }

  @PostMapping("visitorOut/{id}")
  @ApiOperation("访客出场")
  @CommonOperateLogAnnotate(module = LogConstant.LogModule.LABOR_MANAGEMENT, desc = "访客出场")
  public RestMessage visitorOut(@PathVariable String id){
    Assert.notNull(id, "id 不能为空");
    visitorRecordService.visitorOut(id);
    return RestBuilders.successBuilder().build();
  }

  @PostMapping("countByStatus")
  @ApiOperation("通过状态统计来访记录数量")
  public RestMessage countByStatus(@RequestBody VisitorRecordDTO visitorRecordDTO){
    List<VisitorRecordStatusVO> visitorRecordStatusVOList = visitorRecordService.countByStatus(visitorRecordDTO);
    return RestBuilders.successBuilder().data(visitorRecordStatusVOList).build();
  }
}
